import request from "@/utils/request";


/**
 * 上传icon文件
 */
export const uploadArticleFile = (data) => {
    // 确保 FormData 包含 pathPrefix 参数
    if (data instanceof FormData) {
        data.append('pathPrefix', 'article')
    }
    return request({
        url: '/file/file/upload',
        method: 'post',
        data,
        headers: {
            'Content-Type': 'multipart/form-data'
        }
    })
}

/**
 * 提交文章（新增/编辑统一接口）
 */
export const submitArticle = (data) => {
    return request({
        url: '/admin/article/submit',
        method: 'post',
        data
    })
}

/**
 * 获取文章列表
 */
export const getArticleList = (data) => {
    return request({
        url: '/admin/article/pageList',
        method: 'post',
        data
    })
}

/**
 * 获取文章详情
 */
export const getArticleDetail = (articleId) => {
    return request({
        url: `/admin/article/${articleId}`,
        method: 'get'
    })
}

/**
 * 删除文章
 */
export const deleteArticle = (articleId) => {
    return request({
        url: `/admin/article/${articleId}`,
        method: 'delete'
    })
}

/**
 * 开启（发布）文章
 */
export const enableArticle = (data) => {
    return request({
        url: '/admin/article/enable',
        method: 'post',
        data
    })
}

/**
 * 关闭文章
 */
export const disableArticle = (articleId) => {
    return request({
        url: `/admin/article/disable/${articleId}`,
        method: 'post'
    })
}